<!-- 引体向上 -->
<template>
	<view class="container" >
		<view class='one'>	
		    <image :src="imgUrl"  mode='aspectFit'></image>
			<view>1号</view>
			
			<view class="free" v-if="!value1">
				<view class="takePlace"></view>
				<view >空闲</view>
			</view>
			
			<view class="busy" v-else>
				<view class="name" >考生：{{name1}}</view>
				<view >成绩：{{value1}}个</view>
			</view>
	    </view>
        <!-- id2name没有就说明空闲 -->
		<view class="two" v-if="number==2">
			<image :src="imgUrl" mode='aspectFit'></image>
			<view>2号</view>
			 
			<view class="free" v-if="!value2">
			 	<view class="takePlace"></view>
			 	<view >空闲</view>
			</view>
			 
			<view class="busy" v-else>
			 	<view class="name" >考生：{{name2}}</view>
			 	<view >成绩：{{value2}}个</view>
			</view>
		</view>
	</view>
	
</template>

<script>
	export default {
		data() {
			return {
				name1:"",
				name2:"",
				value1:null,//成绩
				value2:null,
				number:null,//器材个数
				imgUrl:"",
				timer:null,
				free1:null,
				free2:null,
				p:null,
				mode:null,
			}
		},
		onLoad(p) {
			let _that=this;
			if(p.itemName==="引体向上")  this.imgUrl="../../static/res1.png"
		    if(p.itemName==="仰卧起坐")  this.imgUrl="../../static/push_up.png"
			this.number=p.number;
            this.p=p;
            this.timer=setInterval(()=>{
				_that.request(this.p);
				_that.modeRequest();
				if(_that.mode===0){
					clearInterval(_that.timer);
					uni.redirectTo({
						url: '/pages/index/choose'
					});

				}
            },300) 
		},
		methods:{
			request(p){
				let _that=this;
				_that.$myRequest("/listname/searchStuById2","GET",null,function(res){
					if(res.data.list[0].value===undefined){
						_that.value1=null;
					}
					else{
						_that.name1=res.data.list[0].stu_name;
						_that.value1=res.data.list[0].value;
					}
					
					if(res.data.list[1].value===undefined){
						_that.value2=null;
					}
					else{
						_that.name2=res.data.list[1].stu_name;
						_that.value2=res.data.list[1].value;
					}
					
				})
			},
			modeRequest(){
				let _that = this;
				_that.$myRequest("/args/searchMode","GET",null,(res)=> {
					   _that.mode=res.data.mode
				})
			},
		}
	}
	
</script>

<style>
	.name{
		height:100rpx;
		line-height:100rpx;
		text-align: center;
	}

.container{
	margin-top: 200rpx;
	display:flex;
	flex-direction: row;
	text-align: center;
	justify-content:center;
}
.one,.two{

	margin-left: 25rpx;
	margin-right: 25rpx;
	border-radius: 60rpx;
    padding:50rpx  30rpx;
	/*  阴影 */
	box-shadow: 0 0 20rpx rgba(0, 0, 0, 0.15);
}

image{
	width:250rpx;
	height:300rpx;
	line-height:300rpx;
	
}

.takePlace{
	height:100rpx;
}
</style>
